package designpatterns.adapter.e3;
/**
 *
 * @author Smile.Wu
 * @version 2015-10-19
 */
public abstract class AbstractComputer implements Computer {

	//具体电脑的目标电压
	public abstract int getTargetVoltage();

	/**
	 * 电脑的启动入口
	 * @param source
	 * @return
	 * @throws PowerVoltageException 
	 */
	public void startUp(PowerSource source) throws PowerVoltageException {
		//启动之前，先检查电压，如果是符合要求的稳定电压，则开始启动
		if(checkPowerVoltage(source.supplyPower())) {
			
			//具体电脑的启动流程
			startUp();
		}
	}
	
	//电压检查，当前电压和电脑目标电压
	public boolean checkPowerVoltage(int powerVoltage) throws PowerVoltageException {
		if(getTargetVoltage() == powerVoltage) {
			return true;
		}
		throw new PowerVoltageException("dangerous voltage for computer[voltage=220V]!! you may need a power adapter!");
	}
}
